/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.site.ipodium.action;

import java.util.List;

import javax.inject.Inject;

import net.iwsh.core.utils.ObjectUtils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.us.usws.model.domain.video.Video;
import com.us.usws.service.ro.VideoROService;
import com.us.usws.site.ipodium.share.IpodiumPagination;
import com.us.usws.site.ipodium.share.Pagination;
import com.us.usws.support.uitls.SimpleDataPageUtil;
import com.us.usws.support.uitls.SiteWebContext;

/**
 * Struts2 action
 * @author robot
 */
public class ListVideoAction extends ActionSupport {

	private static Log log = LogFactory.getFactory().getInstance(ListVideoAction.class);

	private static final long serialVersionUID = 1L;

	private static final int pageSize = 3;
	private int pageNo = 1;
	private List<Video> videos;

	private int pageCnt;

	private Pagination pg;

	@Inject
	private VideoROService vS;

	/**
	 * init method
	 * @return
	 */
	public String videoCenter() {
		SiteWebContext swc = new SiteWebContext(ServletActionContext.getRequest(), ServletActionContext.getResponse());
		String uid = swc.getIpodiumUser().getUid();
		int rowCount = vS.getIpodiumVideosCount(uid);
		SimpleDataPageUtil dpu = new SimpleDataPageUtil(pageSize, rowCount);
		dpu.setPageNo(pageNo);

		this.videos = vS.getIpodiumVideos(uid, dpu.getStart(), pageSize);
		this.pageCnt = dpu.getPageCount();
		pg = new IpodiumPagination(pageNo, dpu.getPageCount(), "/ipodium/videoCenter.action");

		log.info("pageNo=" + pageNo + ", result size=" + videos.size());
		log.info(ObjectUtils.toXML(videos));
		return SUCCESS;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public List<Video> getVideos() {
		return videos;
	}

	public void setVideos(List<Video> videos) {
		this.videos = videos;
	}

	public int getPageCnt() {
		return pageCnt;
	}

	public void setPageCnt(int pageCnt) {
		this.pageCnt = pageCnt;
	}

	public Pagination getPg() {
		return pg;
	}

	public void setPg(Pagination pg) {
		this.pg = pg;
	}

	public static int getPagesize() {
		return pageSize;
	}

}